package com.group.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.group.pojo.TbContract;
import com.group.service.ContractService;

@Controller
@RequestMapping("/contractInfo")
public class ContractController {
	@Autowired
	private ContractService contractService;
	//跳转合同管理视图
   @RequestMapping("contract.action")
   public String page(Model model){
	   return "info/customer/contract";
   }
   
	
	@RequestMapping("query.action")
	@ResponseBody
	public List<TbContract> query(TbContract contract) {
		List<TbContract> list = contractService.query(contract);
		return list;
	}
   //查询所有的合同
   @RequestMapping("/getAllContract.action")
   @ResponseBody
   public List<TbContract> getAllcontract(Model model){
	   List<TbContract> list = contractService.query();
	   return list;
   }
   //通过合同id查询合同的信息
   @RequestMapping("/getContractById.action")
   @ResponseBody
   public TbContract getContractById(String id){
	   return contractService.getContractById(id);
   }
   //通过设备id查询设备的名称
   @RequestMapping("/getdeviceNameById.action")
   @ResponseBody
   public String deviceName(String id){
  	 return contractService.querydeviceName(id);
   }
   //添加新的合同
   @RequestMapping("/save.action")
   @ResponseBody
   public Map<String,String> save(TbContract contract,HttpServletRequest request){
	   return contractService.save(contract, request);
   }
   //添加新的合同
   @RequestMapping("/update.action")
   @ResponseBody
   public Map<String,String> update(TbContract contract){
	   Map<String, String> map =  contractService.update(contract);
	   return map;
   }
   //删除合同信息
   @RequestMapping("contract/batchDelete.action")
   @ResponseBody
   public Map<String,String> deleteContractInfo(@RequestParam(value = "contractIds[]")String[] contractIds){
	   return contractService.deleteContractInfo(contractIds);
   }
   //修改合同(增加保修时长)
   @RequestMapping("/updateContractSave.action")
   @ResponseBody
   public Map<String,String> updateContractSave(TbContract contract,String deviceName){
	   return contractService.updateContractSave(contract,deviceName);
   }
 //根据客户id和设备id查询合同
   @RequestMapping("/getcontractByDeviceIdAndCustomerId.action")
   @ResponseBody
   public List<TbContract> getcontractByDeviceIdAndCustomerId(String deviceId,String customerId){
	   return contractService.getcontractByDeviceIdAndCustomerId(deviceId,customerId);
   }
}
